package com.gonsin.gview.model.form;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.gonsin.gview.model.GFormItemModel;
import com.gonsin.i18n.logic.T;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@ApiModel("文本框")
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class GLabelModel extends GFormItemModel {

    @ApiModelProperty("text_input表示文本框，还有check_box\\file\\radio\\rich_text\\text_input\\tree_check_box\\tree_selector")
    private String itemType = "label";

    @ApiModelProperty("显示对应的值")
    private String keyName;

    @ApiModelProperty("显示字段名称")
    private String name;

    @ApiModelProperty("和keyName作用相同，keyName是直接显示对应的字段，value是动态显示字段值\n" +
            "使用mustache注入，如果value为\"\"时，显示keyName对应的值，如果value非空时显示value的内容\n" +
            "用法例如：\n" +
            "{{item.createTime}}\n" +
            "/files/{{filename}}")
    private String value;

    @ApiModelProperty("根据情况显示")
    private String showIf;



    @Override
    public GFormItemModel tClone() {
        GLabelModel model = new GLabelModel();
        BeanUtil.copyProperties(this, model, CopyOptions.create().setIgnoreNullValue(true));
        if(name != null){
            model.setName(T.t(name));
        }
//        model.setPlaceholder(T.t(placeholder));
        return model;
    }
}
